import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '../layout/index.vue'
import LayoutAdmin from '../layout_admin/index.vue'
Vue.use(VueRouter)

export const createRouter = (i18n) => {
    const router = new VueRouter({
        mode: 'history', 
        routes:[
            
            {
                path:'/',
                redirect:'/home',
                component:Layout,
                children:[
                    {
                        path: "/redirect/:path*",
                        component:()=>import('@/pages/redirect'),
                    },
                    {
                        path:'/home',
                        name:'home',
                        meta:{
                            title:i18n.t('home')
                        },
                        component:()=>import('@/pages/main/Home'),
                    },
                    {
                        path:'/news',
                        name:'news',
                        meta:{
                            title:i18n.t('news')
                        },
                        component:()=>import('@/pages/main/News'),
                    },
                    {
                        path:'/news/:id',
                        name:'newsdetail',
                        meta:{
                            title:i18n.t('news')
                        },
                        component:()=>import('@/pages/main/NewsDetail'),
                    },
                    {
                        path:'/about',
                        name:'about',
                        meta:{
                            title:i18n.t('about')
                        },
                        component:()=>import('@/pages/main/About'),
                    },
                    {
                        path:'/product',
                        name:'product',
                        meta:{
                            title:i18n.t('product')
                        },
                        component:()=>import('@/pages/main/Product'),
                    },
                    {   
                        path: '/product/detail/*',
                        name:'productdetail',
                        component:()=>import('@/pages/main/ProductDetail'),
                    },
                    {
                        path:'/case',
                        name:'case',
                        meta:{
                            title:i18n.t('case')
                        },
                        component:()=>import('@/pages/main/Case'),
                    },
                    {
                        path:'/hse',
                        name:'hse',
                        meta:{
                            title:i18n.t('hse')
                        },
                        component:()=>import('@/pages/main/HSE'),
                    },
                    {
                        path:'/contactus',
                        name:'contactus',
                        meta:{
                            title:i18n.t('contactus')
                        },
                        component:()=>import('@/pages/main/Contactus'),
                    },
                    {
                        path:'/joinus',
                        name:'joinus',
                        meta:{
                            title:i18n.t('joinus')
                        },
                        component:()=>import('@/pages/main/Joinus'),
                    },
                    {
                        path:'/investor',
                        name:'investor',
                        meta:{
                            title:i18n.t('investor')
                        },
                        component:()=>import('@/pages/main/Investor'),
                    },
                    
                ]
            },
            {
                path:'/admin',
                redirect:'/admin/newslist',
                component:LayoutAdmin,
                children:[
                    {
                        path:'/admin/newslist',
                        name:'newslist',
                        meta:{
                            title:i18n.t('investor')
                        },
                        component:()=>import('@/pages/admin/NewsList')
                    },
                    {
                        path:'/admin/hire',
                        name:'hire',
                        meta:{
                            title:i18n.t('investor')
                        },
                        component:()=>import('@/pages/admin/Hire')
                    },
                    {
                        path:'/admin/message',
                        name:'message',
                        meta:{
                            title:i18n.t('investor')
                        },
                        component:()=>import('@/pages/admin/Message')
                    },
                ]
            },
            {
                path:'/admin/login',
                name:'login',
                meta:{
                    title:i18n.t('investor')
                },
                component:()=>import('@/pages/admin/login')
            },
            {
                path:'*',
                name:'404',
                component:()=>import('@/pages/404')
            }
        ]
    })

    return router
}